package com.xys.auth.service.impl;

import com.xys.auth.bean.Role;
import com.xys.auth.mapper.RoleMapper;
import com.xys.auth.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class RoleServiceImpl implements IRoleService {

    @Autowired
    RoleMapper roleMapper;

    @Override
    public List<Role> findAll() {
       return roleMapper.findAll();
    }

    @Override
    public int save(Role role) {
        role.setId(UUID.randomUUID().toString().replace("-",""));
        return roleMapper.insert(role);
    }

    @Override
    public List<Role> findOtherRole(String id) {
        return  roleMapper.findOtherRole(id);
    }

    @Override
    public void addPermissionToRole(String roleId, String[] ids) {
        for (int i = 0; i < ids.length; i++) {
            roleMapper.addPermissionToRole(roleId,ids[i]);
        }
    }

    @Override
    public Role findById(String id) {
        return roleMapper.findById(id);
    }
}
